package com.kexinde.wjifen.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

/**
 * 
 * @author wei
 * 
 * 商店
 *
 */
@Entity
public class Shop {
	private long id; // 店铺编号（主键）
	private String shopName;  // 店铺名
	private int purview;  // 权限
	private String email;  // 邮箱
	private String phone;  // 联系电话
	private String logoPath;  // logo
	private String profile;  // 简介
	private Address address;  // 地址
	private List<Shopkeeper> shopkeepers = new ArrayList<Shopkeeper>();  // 商家
	private List<Gift> gifts = new ArrayList<Gift>();  // 商品
	private List<Activity> activities = new ArrayList<Activity>();  // 活动信息
	private List<Worker> workers = new ArrayList<Worker>(); // 工作人员
	private List<NormalUser> normalUsers = new ArrayList<NormalUser>();  // 普通用户
	private List<ConsumptionRecord> consumptionRecords = new ArrayList<ConsumptionRecord>(); // 消费记录
	private double registerMoney;  // 注册金额
	
	public Shop(){}

	@Id
	@GeneratedValue
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getShopName() {
		return shopName;
	}

	public void setShopName(String shopName) {
		this.shopName = shopName;
	}

	public int getPurview() {
		return purview;
	}

	public void setPurview(int purview) {
		this.purview = purview;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getLogoPath() {
		return logoPath;
	}

	public void setLogoPath(String logoPath) {
		this.logoPath = logoPath;
	}

	public String getProfile() {
		return profile;
	}

	public void setProfile(String profile) {
		this.profile = profile;
	}

	@OneToOne(cascade=CascadeType.ALL)
	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	@OneToMany(mappedBy="shop",cascade=CascadeType.ALL)
	public List<Shopkeeper> getShopkeepers() {
		return shopkeepers;
	}

	public void setShopkeepers(List<Shopkeeper> shopkeepers) {
		this.shopkeepers = shopkeepers;
	}

	@OneToMany(mappedBy="shop",cascade=CascadeType.ALL)
	public List<Gift> getGifts() {
		return gifts;
	}

	public void setGifts(List<Gift> gifts) {
		this.gifts = gifts;
	}

	@OneToMany(mappedBy="shop",cascade=CascadeType.ALL)
	public List<Activity> getActivities() {
		return activities;
	}

	public void setActivities(List<Activity> activities) {
		this.activities = activities;
	}

	@OneToMany(mappedBy="shop",cascade=CascadeType.ALL)
	@JoinColumn(name="shop_id")
	public List<Worker> getWorkers() {
		return workers;
	}

	public void setWorkers(List<Worker> workers) {
		this.workers = workers;
	}

	@ManyToMany(cascade=CascadeType.ALL)
	@JoinTable(
			   name="shoppoint",
			   joinColumns=@JoinColumn(name="shop_id"),
			   inverseJoinColumns=@JoinColumn(name="normalUser_id")
			   )
	public List<NormalUser> getNormalUsers() {
		return normalUsers;
	}

	public void setNormalUsers(List<NormalUser> normalUsers) {
		this.normalUsers = normalUsers;
	}

	public double getRegisterMoney() {
		return registerMoney;
	}

	public void setRegisterMoney(double registerMoney) {
		this.registerMoney = registerMoney;
	}

	@OneToMany(mappedBy="shop",cascade=CascadeType.ALL)
	public List<ConsumptionRecord> getConsumptionRecords() {
		return consumptionRecords;
	}

	public void setConsumptionRecords(List<ConsumptionRecord> consumptionRecords) {
		this.consumptionRecords = consumptionRecords;
	}

	@Override
	public String toString() {
		return "Shop [id=" + id + ", shopName=" + shopName + ", purview="
				+ purview + ", email=" + email + ", phone=" + phone
				+ ", logoPath=" + logoPath + ", profile=" + profile
				+ ", address=" + address + ", shopkeepers=" + shopkeepers
				+ ", gifts=" + gifts + ", activities=" + activities
				+ ", workers=" + workers + ", normalUsers=" + normalUsers
				+ ", consumptionRecords=" + consumptionRecords
				+ ", registerMoney=" + registerMoney + "]";
	}
	
}
